/******************************************************************************
*  Filename:       rf_patch_mce_wmbus_smode.h
*
*  Description: RF core patch for CC13x2 WMBUS S-Mode
*
*  Copyright (c) 2015-2020, Texas Instruments Incorporated
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions are met:
*
*  1) Redistributions of source code must retain the above copyright notice,
*     this list of conditions and the following disclaimer.
*
*  2) Redistributions in binary form must reproduce the above copyright notice,
*     this list of conditions and the following disclaimer in the documentation
*     and/or other materials provided with the distribution.
*
*  3) Neither the name of the ORGANIZATION nor the names of its contributors may
*     be used to endorse or promote products derived from this software without
*     specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
*  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
*  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
*  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
*  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
*  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
*  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
*  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
*  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*  POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/

#include <stdint.h>
#include "rf_patch_mce_wmbus_smode.h"
#include <ti/devices/DeviceFamily.h>
#include DeviceFamily_constructPath(inc/hw_types.h)

#ifndef MCE_PATCH_TYPE
#define MCE_PATCH_TYPE static const uint32_t
#endif

#ifndef PATCH_FUN_SPEC
#define PATCH_FUN_SPEC
#endif

#ifndef RFC_MCERAM_BASE
#define RFC_MCERAM_BASE 0x21008000
#endif

#ifndef MCE_PATCH_MODE
#define MCE_PATCH_MODE 0
#endif

MCE_PATCH_TYPE patchWmbusStmodeMce[473] = {
   0x2fcf6042,
   0x030c3f9d,
   0x070c680a,
   0x003f0002,
   0x8080ff00,
   0x0014002a,
   0x00160006,
   0x001c002c,
   0x000e0034,
   0x001a0026,
   0x000d0032,
   0x00190025,
   0x000b0031,
   0x00130023,
   0x00000029,
   0x00070003,
   0x00003d1f,
   0x04000000,
   0x0000000f,
   0x000b0387,
   0x004340f4,
   0x00828000,
   0x06700080,
   0x091e0000,
   0x00040510,
   0x02000005,
   0x00613e10,
   0x002f0000,
   0x027f3030,
   0x00000000,
   0x00000000,
   0x00000000,
   0x0000aa00,
   0x67a57223,
   0xa4e5a35d,
   0x73057303,
   0x73047203,
   0x72047306,
   0x72917391,
   0xfff0b008,
   0x90103120,
   0x720da008,
   0x720f720e,
   0xb0d07210,
   0xb1107100,
   0x721ba0d0,
   0x10208162,
   0x06703952,
   0x16300020,
   0x14011101,
   0x60786c01,
   0x60fd6079,
   0x607862f9,
   0x60786078,
   0x12106078,
   0x73117223,
   0x73137312,
   0x81b17314,
   0x91b00010,
   0x6057b070,
   0xc030606d,
   0xc1e167ab,
   0xc4e0c2b2,
   0x6f131820,
   0x16116e23,
   0x687f1612,
   0x9c807830,
   0x9c907840,
   0x9ca07850,
   0x97907860,
   0x94807890,
   0x83309490,
   0xc5129cb0,
   0x1820c750,
   0x12034099,
   0x16126e23,
   0x78c06896,
   0x72639990,
   0x606db63c,
   0x96408190,
   0x39808170,
   0x10012a70,
   0x84a21611,
   0xc0f384b4,
   0xc200c0f5,
   0x40c21c01,
   0x1c10c100,
   0x4cba40b8,
   0x18031013,
   0x1a131830,
   0x39121a10,
   0x60c268b5,
   0x60c213f3,
   0x101513f3,
   0x1850c100,
   0x1a101a15,
   0x68c03914,
   0x7100b0e8,
   0xa0e8b128,
   0xb910b230,
   0x99308990,
   0xb0d1b111,
   0xb0027100,
   0xb111b012,
   0x7291a0d1,
   0xb003b630,
   0x722cb013,
   0x7100b0e0,
   0x8170b120,
   0x710092c0,
   0x8170b120,
   0x44db22f0,
   0x1c0313f0,
   0x92c340e7,
   0x71009642,
   0x92c5b120,
   0x71009644,
   0xb0e0b120,
   0x7000a630,
   0xc030a0e1,
   0xc0409910,
   0xb1119930,
   0x7100b0d1,
   0xa0d1b111,
   0xa0037291,
   0xa230a002,
   0x73117000,
   0x87917312,
   0xd0400631,
   0x67ab9a11,
   0x91f0c100,
   0xb633649e,
   0x06308790,
   0x41541e10,
   0x412f1e20,
   0xb0d3b113,
   0xc030b634,
   0xb12191f0,
   0xc005b0e1,
   0x22d08ca0,
   0x12f5411a,
   0x22308090,
   0x81d0454f,
   0xc0d10850,
   0x6f121401,
   0x2252c063,
   0x12114127,
   0x13f16128,
   0xb12192f1,
   0x31127100,
   0x45231a13,
   0xb113611a,
   0xb634b0d3,
   0x91f0c000,
   0xb0e1b121,
   0x39858ca5,
   0x06153955,
   0x22308090,
   0x81d0454f,
   0x06100850,
   0x13f04144,
   0x61461211,
   0x13f11210,
   0x101b100a,
   0xb12192f0,
   0x92f17100,
   0x7100b121,
   0xa0e1613a,
   0xa0d3b121,
   0x606d64ee,
   0xb630b0e0,
   0x92c0c070,
   0x964078a0,
   0x7100b120,
   0xa0e0b120,
   0xb633a630,
   0xb0d3b113,
   0xa0d37100,
   0x606d64ee,
   0xb016b006,
   0xb014b004,
   0xb012b002,
   0x78728440,
   0x81730420,
   0x2a733983,
   0xc1f294e3,
   0x31621832,
   0x31511021,
   0x00200012,
   0x10309440,
   0x39301610,
   0x41812210,
   0x31501220,
   0x31801003,
   0x93801630,
   0x12041202,
   0x41932273,
   0x997084a0,
   0x1a828982,
   0x997084c0,
   0x1a848984,
   0x22636195,
   0x84b041a0,
   0x89809970,
   0x14021a80,
   0x997084d0,
   0x1a808980,
   0x61ac1404,
   0x788184b0,
   0x99700410,
   0x1a428982,
   0x788184d0,
   0x99700410,
   0x1a448984,
   0x31543152,
   0x06333963,
   0x38321613,
   0x31823834,
   0x31843982,
   0x97220042,
   0x959084a0,
   0x95a084b0,
   0x95b084c0,
   0x95c084d0,
   0x90307810,
   0x78209050,
   0x90609040,
   0x8cb2b235,
   0x93328333,
   0x9a12e050,
   0x67ab9a23,
   0xc00bc00c,
   0x720e720d,
   0xb121720f,
   0x7100b0e1,
   0xa0e1b072,
   0xb06ea04e,
   0xb06cb011,
   0x7291993a,
   0xa914b914,
   0x9912c662,
   0xc028c04f,
   0x7100667a,
   0xb910b073,
   0x220780b7,
   0xa910461c,
   0x22f18c81,
   0x223741f6,
   0xb13341f6,
   0x223080b0,
   0x620445f1,
   0x420922e1,
   0x22508090,
   0xb1154209,
   0x22208240,
   0x993941e5,
   0xa914b914,
   0x61e5b116,
   0xb914993d,
   0xb116a914,
   0x8ca061e5,
   0x421522f0,
   0x42152237,
   0xb133b075,
   0x223080b0,
   0xb087460f,
   0x22d161e5,
   0x809042bd,
   0x42bd2220,
   0x61e56640,
   0xa009993f,
   0xa0f0a008,
   0xa0d2a0f3,
   0xb111a0d5,
   0xa0d6b0d1,
   0x99387100,
   0xba3fb111,
   0x87208b11,
   0x97011801,
   0x8c418c30,
   0xa637a638,
   0x22e08ca0,
   0x82404238,
   0x45d02220,
   0xb04e7100,
   0xb074b06e,
   0x8c43b231,
   0x70008702,
   0x22b08c80,
   0x1e3b4646,
   0x62484678,
   0x46781e7b,
   0xba39c00b,
   0x31808af0,
   0x16403d80,
   0x140c3d30,
   0x220080b0,
   0x70004254,
   0x39838c83,
   0x8c8106f3,
   0x0401cff0,
   0x1c1c3031,
   0x12004e70,
   0x1c0c1810,
   0x80b04a72,
   0x42652200,
   0x10c27000,
   0x3c321612,
   0x83508cb1,
   0x42742210,
   0x93316276,
   0x7000b112,
   0x6261101c,
   0x6261100c,
   0x626d1821,
   0x626d1421,
   0x626e161b,
   0xb111b116,
   0xb133b130,
   0xb112b115,
   0x720e720d,
   0xb0f0720f,
   0x8c82b0f3,
   0x428b22f2,
   0xb913b0d6,
   0x8ca0628e,
   0x42ae22f0,
   0xa444b445,
   0xa469b468,
   0x3180caa0,
   0x0001caa1,
   0x94d194c1,
   0x31838ca3,
   0x84503983,
   0x39803180,
   0x00303183,
   0x84409450,
   0x39503150,
   0x39838ca3,
   0xc1f406f3,
   0x31841834,
   0x00403134,
   0xb0899440,
   0x42b822e2,
   0x394a8c9a,
   0x312a398a,
   0xb0d5993a,
   0xb913b0d6,
   0x22d28c82,
   0xb0d242bc,
   0xb23f7000,
   0xa0f3a0f0,
   0xb914993e,
   0xb116a914,
   0xb133b130,
   0x22f08240,
   0xb11542c6,
   0xa0048002,
   0xa001a006,
   0x72047203,
   0x67abc060,
   0xb9147100,
   0xb0d5b116,
   0x7100a23f,
   0xa0d5b115,
   0x90307810,
   0x78209002,
   0x90609040,
   0xa23fb072,
   0x993a667a,
   0xb116a914,
   0xba3c61e5,
   0x8b5481b0,
   0x31843924,
   0x91b40004,
   0x67abc070,
   0x72917391,
   0x720667a5,
   0x72047202,
   0x73067305,
   0x8240606d,
   0x47012230,
   0x7100b0d5,
   0xa0d5b115,
   0x8c8162f9,
   0x430a22c1,
   0x67abc080,
   0xb008b009,
   0xb018b019,
   0x91e01200,
   0xc090b35d,
   0xb11867ab,
   0xb1116566,
   0xba3eb0d1,
   0xe0a08c43,
   0x9a229a13,
   0x710067ab,
   0xb111a0d1,
   0xb0d2b112,
   0x120ac00f,
   0x1a1f120f,
   0x12031204,
   0x39888ca8,
   0x06183958,
   0xb1127100,
   0x8ce0ba3d,
   0x3d803180,
   0x6334100b,
   0x121a120b,
   0x16131a14,
   0xb1127100,
   0x8ce0ba3d,
   0x3d803180,
   0x7100140b,
   0xba3db112,
   0x31808ce0,
   0x140b3d80,
   0x7100100d,
   0xba3db112,
   0x31808ce0,
   0x140b3d80,
   0x100c140d,
   0x4f5122fd,
   0x120d10d0,
   0x7100180d,
   0xba3db112,
   0x31808ce0,
   0x180b3d80,
   0x100e140c,
   0x4f5f22fc,
   0x120c10c0,
   0x7100180c,
   0xba3db112,
   0x31808ce0,
   0x180b3d80,
   0x22fe140e,
   0x10e04f6c,
   0x180e120e,
   0xb1127100,
   0x8ce0ba3d,
   0x3d803180,
   0x7100180b,
   0xba3db112,
   0x31808ce0,
   0x180b3d80,
   0x398b10b6,
   0x088b397b,
   0x161f91cb,
   0x1e008180,
   0x1a104387,
   0x4f871cf0,
   0x67996392,
   0x43911e1a,
   0x43301e4a,
   0xb1127100,
   0x1614121a,
   0x63281613,
   0x9a13e0b0,
   0x67ab9a24,
   0xb112a0d2,
   0xc01a62e7,
   0x140d78b0,
   0x1cec140e,
   0xc03a4ba1,
   0x1cdc10ec,
   0xc04a4ba4,
   0x86307000,
   0x3151c801,
   0x96300410,
   0x9a007000,
   0x220089f0,
   0xb9e047ac,
   0x00007000
};

PATCH_FUN_SPEC void rf_patch_mce_wmbus_smode(void)
{
#ifdef __PATCH_NO_UNROLLING
   uint32_t i;
   for (i = 0; i < 473; i++) {
      HWREG(RFC_MCERAM_BASE + 4 * i) = patchWmbusStmodeMce[i];
   }
#else
   const uint32_t *pS = patchWmbusStmodeMce;
   volatile unsigned long *pD = &HWREG(RFC_MCERAM_BASE);
   uint32_t t1, t2, t3, t4, t5, t6, t7, t8;
   uint32_t nIterations = 59;

   do {
      t1 = *pS++;
      t2 = *pS++;
      t3 = *pS++;
      t4 = *pS++;
      t5 = *pS++;
      t6 = *pS++;
      t7 = *pS++;
      t8 = *pS++;
      *pD++ = t1;
      *pD++ = t2;
      *pD++ = t3;
      *pD++ = t4;
      *pD++ = t5;
      *pD++ = t6;
      *pD++ = t7;
      *pD++ = t8;
   } while (--nIterations);

   t1 = *pS++;
   *pD++ = t1;
#endif
}
